package com.tanhua.server.service;

import com.alibaba.dubbo.config.annotation.Reference;
import com.tanhua.dubbo.server.api.RecommendUserApi;
import com.tanhua.dubbo.server.pojo.RecommendUser;
import com.tanhua.dubbo.server.vo.PageInfo;
import com.tanhua.server.vo.TodayBest;
import org.springframework.stereotype.Service;

@Service
public class RecommendUserService {

    @Reference(version = "1.0.0")
    private RecommendUserApi recommendUserApi;

    public TodayBest queryTodayBest(Long id) {
        RecommendUser recommendUser = recommendUserApi.queryWithMaxScore(id);
        if (null == recommendUser){
            return null;
        }

        TodayBest todayBest = new TodayBest();
        // 将计算得到的小数转换为整数
        double floor = Math.floor(recommendUser.getScore());// 缘分值
        // 再将整数改为Long类型
        todayBest.setFateValue(Double.valueOf(floor).longValue());
        todayBest.setId(recommendUser.getUserId());// 用户id

        return todayBest;
    }

    public PageInfo<RecommendUser> queryRecommendUserList(Long id, Integer page, Integer pagesize) {
        return recommendUserApi.queryPageInfo(id, page, pagesize);
    }

    public double queryScore(Long userId, Long id) {
        return recommendUserApi.queryScore(userId, id);
    }
}
